// JavaScript Document
$(document).ready(function(e) {
    $('.input_image, .customfile-upload').change(function(){
		var selector = $(this);
		var str = selector.val();
		
		var ext=str.substring(str.length,str.length-3);
		if(ext == 'jpg' || ext == 'png' || ext == 'JPG' || ext == 'PNG'){
			if (this.files && this.files[0]) {
				var reader = new FileReader();
									
				reader.onload = function (e) {
					selector.parents('.editor-field').find('.preview-image img').attr('src', '');
					setTimeout(function(){
						selector.parents('.editor-field').find('.preview-image img').attr('src', e.target.result).css({display: "none"}).fadeIn("fast");
					},500);
				};
									
				reader.readAsDataURL(this.files[0]);
			}
		}else{
			alert('Định dạng ảnh không hợp lệ. Chỉ hổ trợ jpg, png.');
			selector.val('');
		}
	});
});
	
	